import 'dart:io';

import 'package:dingtalk/core/blocs/chat/chat_bloc.dart';
import 'package:dingtalk/core/blocs/message_record/message_record_bloc.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

import 'core/values/colors.dart';
import 'ui/screens/main/main_screen.dart';

void main() {
  runApp(MultiBlocProvider(providers: [
    BlocProvider<THChatBloc>(create: (context) => THChatBloc()),
    BlocProvider<THMessageRecordBloc>(
        create: (context) => THMessageRecordBloc()),
  ], child: THApp()));

  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle =
        SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
}

class THApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    _configLoading();
    return MaterialApp(
      title: 'Flutter DingTalk',
      debugShowCheckedModeBanner: false,
      theme: Theme.of(context).copyWith(
          appBarTheme: Theme.of(context).appBarTheme.copyWith(
              color: Colors.white,
              elevation: 0,
              brightness: Brightness.light,
              iconTheme: IconThemeData(color: kColor33),
              actionsIconTheme: IconThemeData(color: kColor33))),
      home: THMainScreen(),
      builder: EasyLoading.init(),
    );
  }

  void _configLoading() {
    EasyLoading.instance
      ..displayDuration = const Duration(milliseconds: 2000)
      ..indicatorType = EasyLoadingIndicatorType.circle
      ..loadingStyle = EasyLoadingStyle.dark
      ..fontSize = 18.0
      ..indicatorSize = 45.0
      ..radius = 10.0
      ..progressColor = Colors.yellow
      ..backgroundColor = Colors.green
      ..indicatorColor = Colors.yellow
      ..textColor = Colors.yellow
      ..maskColor = Colors.blue.withOpacity(0.5)
      ..userInteractions = true
      ..dismissOnTap = false;
  }
}
